import { InputQuestion, QuestionBase, TimeQuestion, SelectQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { DOCUMENT_APPLICATION_STATUS_COLOR } from '@/filters/color';
import { Api } from '@/config/api/documentApplication';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'code',
        label: '单据编号',
        value: null
      }),
      new InputQuestion({
        key: 'fileName',
        label: '文件名称',
        value: null
      }),
      new SelectQuestion({
        key: 'type',
        label: '申请类型',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'DMS_PUBILC_FILE_APPLY_IS_TYPE'
        }
      }),
      new SelectQuestion({
        key: 'status',
        label: '状态',
        value: [],
        type: 'dictionary',
        state: {
          mode: 'multiple',
          filterName: 'DOCUMENT_APPLICATION_STATUS'
        }
      }),
      new TimeQuestion({
        key: 'createdTime',
        label: '申请时间',
        value: [],
        state: {
          showTime: true,
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss',
          keySplit: ['startCreateTime', 'endCreateTime']
        }
      })
    ];
    return questions;
  }
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'num',
        value: '序号',
        type: 'index'
      }),
      new TextTable({
        key: 'code',
        value: '单据编号',
        type: 'router',
        state: {
          type: 'url',
          url: 'documentApplicationAddFile',
          params: [{ id: 'id' }, { processInstanceId: 'approveId' }],
          state: {
            assign: { showType: 'VIEW' }
          }
        }
      }),
      new TextTable({
        key: 'fileName',
        value: '文件名称'
      }),
      new TextTable({
        key: 'type',
        value: '申请类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_PUBILC_FILE_APPLY_IS_TYPE'
        }
      }),
      new TextTable({
        key: 'status',
        value: '状态',
        type: 'dictionary',
        state: {
          filterName: 'DOCUMENT_APPLICATION_STATUS'
        },
        colors: DOCUMENT_APPLICATION_STATUS_COLOR
      }),
      new TextTable({
        key: 'creatorName',
        value: '流程发起人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '发起时间'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        handle: [
          // {
          //   type: 'url',
          //   url: 'documentApplicationAddFile',
          //   text: '审核',
          //   class: 'text-primary',
          //   params: [{ id: 'id' }, { processInstanceId: 'approveId' }],
          //   showKey: [{ key: 'status', value: 2 }],
          //   state: {
          //     params: { showType: 'AUDIT' }
          //   }
          // },
          {
            type: 'hint',
            text: '撤回',
            class: 'text-primary',
            url: Api.fileRevoke,
            postType: 'post',
            urlName: 'id',
            params: [{ id: 'id' }],
            showKey: [{ key: 'status', value: 2 }],
            state: {
              hintData: {
                title: '是否撤回流程？撤回后，不可撤销。'
              }
            }
          },
          // {
          //   type: 'url',
          //   url: 'documentApplicationAddFile',
          //   text: '会签',
          //   class: 'text-primary',
          //   params: [{ id: 'id' }, { processInstanceId: 'approveId' }],
          //   showKey: [{ key: 'status', value: 3 }],
          //   state: {
          //     params: { showType: 'SIGN' }
          //   }
          // },
          {
            type: 'hint',
            text: '关闭流程',
            class: 'text-primary',
            url: Api.fileClose,
            postType: 'post',
            urlName: 'id',
            params: [{ id: 'id' }],
            showKey: [{ key: 'status', value: 4 }],
            state: {
              hintData: {
                title: '是否关闭流程，关闭后，流程中断，不能再被重新发起？'
              }
            }
          },
          {
            type: 'delete',
            text: '删除',
            class: 'text-primary',
            url: Api.fileDelete,
            postType: 'post',
            urlName: 'id',
            params: [{ id: 'id' }],
            showKey: [{ key: 'status', value: 1 }],
            state: {
              title: '是否确定删除你所选择的数据，确定后将直接删除？'
            }
          }
        ]
      })
    ];
    return tables;
  }
  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'router',
        value: '启动申请',
        type: 'primary',
        class: 'PlusOutlined',
        state: {
          url: 'documentApplicationAddFile',
          params: {
            showType: 'ADD'
          }
        }
      })
    ];
    return icons;
  }
}

export default new HomeService();
